// pages/startup/startup.js
const db=wx.cloud.database();
var app=getApp();
Page({
  data: {
    back:'../../img/richang5.jpg',
    back2:'../../img/richang4.jpg',
    hide:true,
    hide2:false,
    hide3:true,
    backani2:'',
    hide_start:false

  },
  handleclick:function(){
  this.setData({
    hide:false,
    hide2:true
  })
  var that=this
  setTimeout(function(){
    that.setData({
      backani2:'heartBeat 90s;'

    })
  },1500)
  },
  start:function(){
    if(app.globalData.not_login==true){
      wx.switchTab({
        url: '../me/me',
      }) 

    }else{
      wx.switchTab({
        url: '../habit/habitEn',
      }) 
    }
  },

  onLoad: function (options) {

  // 判断是否登陆,如果登陆不显示即刻开启
  console.log(app.globalData.not_login)

  db.collection('demo').where({
    _openid:app.globalData.userOpenid                                                                                                            
  }).get().then(res=>{
    console.log(res.data[0].renyishiduan)
    // console.log(res.data[0].zaochenxiguan)
    // console.log(res.data[0].zhongwuxiguan)
    // console.log(res.data[0].xiawuxiguan)
    app.globalData.globalrenyi=res.data[0].renyishiduan
    app.globalData.globalzaochen=res.data[0].zaochenxiguan
    app.globalData.globalzhongwu=res.data[0].zhongwuxiguan
    app.globalData.globalxiawu=res.data[0].xiawuxiguan
  })
  let that=this
    //必须要设置延时，因为页面加载完成后not_login才会传过来，不然一直是false
    setTimeout(function () {
      console.log(app.globalData.not_login)
      if(app.globalData.not_login){
      }
      else{
       that.setData({
          hide_start:true
       })
       that.tiaozhuan()
      }    
    }, 1000)
    // wx.switchTab({
    //   url: '../index/index',
    // })
  },
  tiaozhuan:function(){

    console.log("自动跳转")
    this.setData({
      hide:false,
     
    })
    setTimeout(() => {
      if(app.globalData.not_login==true){
        wx.switchTab({
          url: '../me/me',
        }) 

      }else{
        wx.switchTab({
          url: '../habit/habitEn',
        }) 
      }
          
    }, 3000);
  },
  onReady: function () {
    
  }
})